<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>授权书</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="/static/wx/lib/sui/sm.min.css">
    <link rel="stylesheet" href="/static/wx/lib/sui/sm-extend.min.css">
    <link rel="stylesheet" href="/static/wx/css/reset.css">
    <link rel="stylesheet" href="/static/wx/css/main.css">
    <link rel="stylesheet" href="/static/wx/css/public_main.css">
</head>

<body>
<div class="page-group">
    <div class="page page-current" id="commodityInfo">
        <!-- 主内容 -->
        <div class="content">
            <div class="bs-box">
                <div class="bs-box-content">
                    <div class="bs-box-inner">

                        <div class="bs-box-content-item border-b-none">
                            <p class="size-m">上传委托书</p>
                            <div class="uploader">
                                <ul class="uploader-files" id="uploader-imges">
                                    {foreach($info.entrust_url as $k=>$v)}
                                    <li class="uploader-file" style="background-image:url({$v})">
                                        <span class="close" onclick="deleteT(this)">x</span>
                                    </li>
                                    {/foreach}
                                </ul>
                                <div class="uploader-content">
                                    <div class="uploader-input-box">
                                        <input class="uploader-input" type="file" accept="image/*" onchange="handleInputChange1(event)"/>
                                    </div>
                                </div>

                            </div>
                        </div>

                    </div>
                </div>
            </div>
            <div class="btn-box">
                <div class="my-btn">
                    <input type="hidden" id="policy_num" value="{$info.policy_num | default = ''}">
                    <input type="hidden" id="i_id" value="{$info.i_id | default = ''}">
                    <span class="active" id="submit">保存</span>
                </div>
            </div>
        </div>
    </div>
</div>
<script type='text/javascript' src='/static/wx/lib/sui/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='/static/wx/lib/sui/sm.min.js' charset='utf-8'></script>
<script type='text/javascript' src='/static/wx/lib/sui/sm-extend.min.js' charset='utf-8'></script>
<script type='text/javascript' src='/static/wx/js/upload.js' charset='utf-8'></script>
<script>
    $('#submit').on('touchend',function(){
        var i_id = $('#i_id').val();
        var policy_num = $('#policy_num').val();
        var arr=[];
        $("#uploader-imges  li").each(function(index){
            var i=0;
            var url=$(this).css('background-image');
            url= url.split('("')[1].split('")')[0];
            arr.push(url);
        });

        $.ajax({
            url:'/wx/insurant/saveBolInfo',
            type:'post',
            dataType:'json',
            data:{
                'i_id':i_id,
                'now_status':5,
                'entrust_url':arr
            },
            success:function (data) {
                if(data.code ==200){
                    $.alert('修改成功');
                    window.location.href = '/wx/insurant/returnEdit?policy_num='+policy_num;
                }else{
                    $.alert(data.msg);
                }
            }
        });
    });

    function handleInputChange1(event) {
        var formData = handleInputChange(event);
        uploadImg(formData);

    }
    function  uploadImg(formData) {
        console.log(formData);
        $.ajax({
            type: 'POST',
            url: "{:url('upload/index')}",
            data: formData,
            processData: false,
            contentType: false,
            cache: false,
            success: function (Json) {
                console.log(Json.data)
                if (Json.code == 200) {
                    var url = decodeURI(Json.data.url)
                    a="<li class=\"uploader-file\" style=\"background-image:url('"+url+"')\">";
                    a+= "<span class=\"close\" onclick='deleteT(this) '>x</span>"
                    a+= "</li>"
                    $('#uploader-imges').append(a);
                } else {
                    $.alert('上传失败');
                }
            }
        });
    }


    function deleteT(obj) {
        $(obj).parent('li').remove();
    }
</script>
</body>

</html>